package com.zoran.study.spring.helper;


import com.zoran.study.spring.model.Author;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.annotation.Order;

/**
 * MySpringBeanProcessor
 *
 * @author zouxm
 * @date 16/12/17
 */

/**
 * Spring Bean 后置处理器 对所有的bean都会进行处理 在bean初始化方法的前后执行(init)
 */

@Order(value = 1)
public class MySpringBeanProcessor implements BeanPostProcessor {

    public MySpringBeanProcessor() {
        System.out.println("【 construct MySpringBeanProcessor。。。 】");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Author) {
            System.out.println("beanName:" + beanName + ",author bean before post process ...");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Author) {
            System.out.println("author bean after processor ,bean name:" + beanName);
        }
        return bean;
    }


}
